<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

use App\JsonRpc\TestServiceInterface;

use function Hyperf\Support\value;

$registry = [
    'protocol' => 'nacos',
    'address' => 'http://'.env("NACOS_HOST").":".env("NACOS_PORT"),
];
return [
    'enable' => [
        // 开启服务发现
        'discovery' => true,
        // 开启服务注册
        'register' => true,
    ],
    // 服务消费者相关配置
    'consumers'  => value(function () use($registry) {
        $consumers = [];
        $services = [
            'CalculatorService' => TestServiceInterface::class,
        ];
        foreach ($services as $name => $interface) {
            $consumers[] = [
                'protocol' => 'jsonrpc-http',
                'name' => $name,
                'load_balancer' => 'random',
                'service' => $interface,
                'registry' => $registry
            ];
        }
        return $consumers;
    }),
    'drivers' => [
        'nacos' => [
            'host' => env("NACOS_HOST", '127.0.0.1'),
            'port' => env("NACOS_PORT", 8848),
            'username' => null,
            'password' => null,
            'guzzle' => [
                'config' => null,
            ],
            'group_name' => "DEFAULT_GROUP",
            'namespace_id' => env("NACOS_CONFIG_DATA_TENANT"),
            'heartbeat' => 5,
            'ephemeral' => false, // 是否注册临时实例
        ],
    ]
];
